<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
        body, html{width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
        #allmap {height:1000px; width: 100%;}
        #control{width:100%;}
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=D1aKBWDNap6FnXHZgI5MY7OthZFbbnOl"></script>
    <title>路线的生成</title>
</head>

<body>
<div id="allmap"></div>
<script type="text/javascript">

    var map = new BMap.Map("allmap");
    var point = new BMap.Point(117.138596, 36.680859);
    map.centerAndZoom(point, 16);
    map.enableScrollWheelZoom();



    var myP1 = new BMap.Point(117.132165, 36.679128);  //雅居园
    var myP2 = new BMap.Point(117.138598, 36.680855);  //齐鲁软件园
    var myP3 = new BMap.Point(117.141957, 36.675133);  //科汇大厦
    var myP4 = new BMap.Point(117.14767, 36.669966);   //建设银行

    var p = [];  //折线点的集合
    var driver = new BMap.DrivingRoute(map);
    driver.search(myP1, myP2); 5
    driver.setSearchCompleteCallback(function () {
        var pots = driver.getResults().getPlan(0).getRoute(0).getPath();
        p = p.concat(pots);
        driver.search(myP2, myP3);
        driver.setSearchCompleteCallback(function () {
            var pots = driver.getResults().getPlan(0).getRoute(0).getPath();
            p = p.concat(pots);
            driver.search(myP3, myP4);
            driver.setSearchCompleteCallback(function () {
                var pots = driver.getResults().getPlan(0).getRoute(0).getPath();
                p = p.concat(pots);
                var polyline = new BMap.Polyline(p);
                map.addOverlay(polyline);
                var menu = new BMap.ContextMenu();
                var textMenuItem = [
                    {
                        text: "折线可编辑",
                        callback: function () { polyline.enableEditing(); }
                    },
                    {
                        text: "折线不可编辑",
                        callback: function () { polyline.disableEditing(); }
                    },
                    {
                        text: "编辑完成",
                        callback: function () {
                            var points = polyline.getPath();}
                ];
                for (var i = 0; i < textMenuItem.length; i++) {
                    menu.addItem(new BMap.MenuItem(textMenuItem[i].text, textMenuItem[i].callback, 100));
                }
                map.addContextMenu(menu);
            });
        });
    });
</script>
</body>
</html>